class Solution {
public:
string addSpaces(string s, vector<int>& spaces) 
{
	int n = s.size();
	int length = n + spaces.size();
	string res(length,' ');
	int j = length - 1;
	int i = n - 1;
	int k = spaces.size() - 1;
	while (i >= 0 && j >= i)
	{
		if (k >= 0 && i == spaces[k] - 1)
		{
			--j;
			--k;
			continue;
		}
		else
		{
			res[j] = s[i];
			--j;
			--i;
		}
	}

	return res;
}
};
